package StudyCode.summary.mydatetime;

import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CalendarInterval {
	public static void main(String[] args) {
		Calendar calendar = Calendar.getInstance();
		Calendar calendar1 = Calendar.getInstance();

		calendar1.set(2010, 0, 1, 12, 0);
		Date date1 = calendar1.getTime();
		System.out.println(date1 + "到" + calendar.getTime() + "共有:");

		long mill = Math.abs(calendar.getTimeInMillis() - date1.getTime());
		long hours = TimeUnit.MILLISECONDS.toHours(mill);
		Long days = TimeUnit.HOURS.toDays(hours);
		String diff = String.format("%d 小时 %d 分钟", hours, TimeUnit.MILLISECONDS.toMinutes(mill) - TimeUnit.HOURS.toMinutes(hours));
		System.out.println(diff);

		diff = String.format("%d 天", days);
		System.out.println(diff);

		int weeks = days.intValue() / 7;
		diff = String.format("%d 周", weeks);
		System.out.println(diff);
	}
}
